package part2;

import java.util.ArrayList;
import java.util.Deque;
import java.util.LinkedList;
import java.util.List;

/**
 * @Author: shaochong
 * @Date: 2021/8/15
 * @Description:
 */
public class Slution101 {
    public static class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;
        TreeNode() {}
        TreeNode(int val) { this.val = val; }
        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }

    public boolean isSymmetric(TreeNode root) {
        if(root.left == null && root.right == null) {
            return true;
        }
        if (root.left == null || root.right == null) {
            return false;
        }
        return root.left.val == root.right.val && isSymmetric(root.left) && isSymmetric(root.right);
    }


    public boolean isSymmetric2(TreeNode root) {
        return check(root.left, root.right);
    }

    public boolean check(TreeNode t1, TreeNode t2) {
        if (t1 == null && t2==null) return true;
        if (t1 == null || t2 == null) return false;
        return t1.val == t2.val && check(t1.left, t2.right) && check(t1.right, t2.left);
    }
}
